package com.ftx.controller.pc;

import com.ftx.common.enums.ArticleOpennessEnum;
import com.ftx.common.enums.ArticleTypeEnum;
import com.ftx.domain.vo.ArticleVO;
import com.ftx.domain.vo.RespnseResult;
import com.ftx.manager.tag.TagManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by fengtingxin on 2019/6/11.
 */
@Controller
@RequestMapping(value = "/article")
public class ArticleController {

    private static final Logger logger = LoggerFactory.getLogger(ArticleController.class);

    @Resource
    private TagManager tagManager;

//    @Resource
//    private Article


    /**
     * 跳转到发布文章页面
     */
    @RequestMapping(value = "/toPublish",method = RequestMethod.GET)
    public ModelAndView toPublish(ModelMap model){
        ModelAndView modelAndView = new ModelAndView("/front/publish",model);
        //1.获取所有的分类
//        model.addAttribute("allCategory",);
        //2.获取所有的标签
        model.addAttribute("tags",tagManager.listAllTags());
        model.addAttribute("articleTypeEnum", ArticleTypeEnum.values());
        model.addAttribute("articleOpennessEnum", ArticleOpennessEnum.values());
        return modelAndView;
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public RespnseResult add(ArticleVO articleVO){
        //1.获取所有的分类
//        model.addAttribute("allCategory",);
        //2.获取所有的标签
        logger.info("i'm in ");
        logger.info("article is {}",articleVO);

        return new RespnseResult(1);
    }
}
